package com.zj.system.controller;

import com.seventh.common.pojo.R;
import com.zj.system.aop.LogAnnotation;
import com.zj.system.pojo.entity.Role;
import com.zj.system.pojo.entity.User;
import com.zj.system.pojo.vo.RoleVo;
import com.zj.system.service.RoleService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: clms-seventh
 * @description: 角色表的控制层
 * @author: 张静
 * @create: 2021-07-19 19:31
 **/
@RestController
@RequestMapping("system/role")
@ApiModel(value = "角色控制层",description = "角色控制层")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("sel/{userId}")
    @ApiModelProperty("根据用户id查找所拥有的角色信息")
    @LogAnnotation(title ="角色接口", action ="根据用户id查找所拥有的角色信息",businessType = "0")
    public R selRole(@ApiParam("用户ID")@PathVariable("userId") Integer userId){
        return roleService.selRole(userId);
    }
    @GetMapping("insRole/{userId}")
    @ApiModelProperty("为用户分配角色")
    @LogAnnotation(title ="角色接口", action ="为用户分配角色",businessType = "1")
    public R insertRole(@ApiParam("用户ID")@PathVariable("userId") Integer userId,
                        @ApiParam("角色ID数组")@RequestParam List<Integer> userRole){
        return roleService.upUserRole(userId, userRole);
    }
    @PostMapping("sel/{currentPage}/{pageSize}")
    @ApiModelProperty("搜索分页查询角色")
    @LogAnnotation(title ="角色接口", action ="搜索分页查询角色",businessType = "0")
    public R selR(@ApiParam("当前显示的页码")@PathVariable("currentPage") Integer currentPage,
                  @ApiParam("每页显示的条数")@PathVariable("pageSize") Integer pageSize,
                  @ApiParam("前端传入的搜索数据")@RequestBody RoleVo roleVo){
        return roleService.sel( pageSize,currentPage, roleVo);
    }
    @PutMapping("up/{roleId}/{status}")
    @ApiModelProperty("更新角色的状态")
    @LogAnnotation(title ="角色接口", action ="更新角色的状态",businessType = "2")
    public R upStatus(@ApiParam("角色ID")@PathVariable("roleId") Integer roleId,
                      @ApiParam("角色状态值")@PathVariable("status") Integer status){
        return roleService.upStatus(roleId,status);
    }
    @PutMapping("updateRoleById")
    @ApiModelProperty("更新角色信息")
    @LogAnnotation(title ="角色接口", action ="更新角色信息",businessType = "2")
    public R update(@ApiParam("角色信息")@RequestBody Role role){
        return roleService.up(role);
    }
    @PostMapping("insertRole")
    @ApiModelProperty("新增角色信息")
    @LogAnnotation(title ="角色接口", action ="新增角色信息",businessType = "1")
    public R insertUser(@ApiParam("角色信息")@RequestBody Role role){
        return roleService.ins(role);
    }
    @GetMapping("selById/{roleId}")
    @ApiModelProperty("根据角色ID查询角色信息")
    @LogAnnotation(title ="角色接口", action ="根据角色ID查询角色信息",businessType = "0")
    public R selById(@ApiParam("角色ID")@PathVariable("roleId") Integer roleId){
        return roleService.selById(roleId);
    }
    @DeleteMapping("del/{roleId}")
    @ApiModelProperty("根据角色ID删除角色信息")
    @LogAnnotation(title ="角色接口", action ="根据角色ID删除角色信息",businessType = "3")
    public R del(@ApiParam("角色ID")@PathVariable("roleId") Integer roleId){
        return roleService.del(roleId);
    }
    @PostMapping("selRoleName")
    @ApiModelProperty("查询角色名是否唯一")
    @LogAnnotation(title ="角色接口", action ="查询角色名是否唯一",businessType = "0")
    public R selRoleName(@ApiParam("角色信息")@RequestBody Role role){
        return roleService.selRoleName(role);
    }
}
